// Generator
<template>
  <div>
    <prism language="javascript">
      function* dp() {
      yield "maicai";
      yield "zecai";
      yield "huomian";
      yield "baojiaozi";
      return "dp";
      }
      let jiaozi = dp();

      //generator从头走到尾，除非重新创建一个新的
      // for(i of jiaozi){
      //     console.log(i);
      // }

      console.log(typeof jiaozi);
      let a = jiaozi.next(); //执行
      console.log(a.value);
      let b = jiaozi.next();
      console.log(b.value);
      let c = jiaozi.next();
      let d = jiaozi.next();
      let e = jiaozi.next();
      let f = jiaozi.next();
      console.log(c, d, e, f);
    </prism>
    <v-btn
      round
      color="success"
      @click="run"
    >
      RUN
    </v-btn>
  </div>
</template>

<script>
import Prism from "vue-prism-component";
export default {
  components: {
    Prism
  },
  methods: {
    run() {
      function* dp() {
        yield "maicai";
        yield "zecai";
        yield "huomian";
        yield "baojiaozi";
        return "dp";
      }
      let jiaozi = dp();

      //generator从头走到尾，除非重新创建一个新的
      // for(i of jiaozi){
      //     console.log(i);
      // }

      console.log(typeof jiaozi);
      let a = jiaozi.next(); //执行
      console.log(a.value);
      let b = jiaozi.next();
      console.log(b.value);
      let c = jiaozi.next();
      let d = jiaozi.next();
      let e = jiaozi.next();
      let f = jiaozi.next();
      console.log(c, d, e, f);
    }
  }
};
</script>